package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "护理计划管理")
@RequestMapping("/nursing/plan")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanDto>> getAll() {
        List<NursingPlanVo> data = nursingPlanService.getAll();
        return success(data);
    }


    @PostMapping("/plan")
    @ApiOperation("新增护理计划")
    public ResponseResult add(
            @ApiParam(value = "护理计划数据传输对象", required = true)
            @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.add(nursingPlanDto);
        return success();
    }

    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult pageSearch(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name",required = false) String name,
            @ApiParam(value = "状态: 0-禁用,1-启用")
            @RequestParam(value = "status",required = false) Integer status,
            @ApiParam(value = "页码（默认为1）")
            @RequestParam(value = "pageNum", defaultValue = "1")Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10")Integer pageSize) {
        PageResponse<NursingPlanVo> nursingPlanPageInfo =  nursingPlanService.getByPage(name,status,pageNum,pageSize);
        return success(nursingPlanPageInfo);
    }


    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult getById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return success(nursingPlanVo);
    }

    @PutMapping("/{id}")
    @ApiOperation("根据id修改护理计划")
    public ResponseResult updateById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id,
            @ApiParam(value = "护理计划内容", required = true)
            @RequestBody NursingPlanDto nursingPlanDto){

            nursingPlanService.updateById(id,nursingPlanDto);
        return success();
    }


    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult deleteById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id){

        nursingPlanService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理计划状态")
    public ResponseResult changeStatus(
            @ApiParam(value = "护理等级ID", required = true)
            @PathVariable Long id,
            @ApiParam(value = "状态，0：禁用，1：启用", required = true)
            @PathVariable Integer status){

        nursingPlanService.changeStatus(id,status);
        return success();
    }


}

